﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Aioms.Common;
using Aioms.Dtos;
using Aioms.Models;
using Mapster;

namespace Aioms.Mapper
{
    public class TaskPlanGongDanListExportMapper : IRegister
    {
        public void Register(TypeAdapterConfig config)
        {
            config.ForType<TpWorkOrder, TaskPlanGongDanListExportDto>()
                .Map(tpgdle => tpgdle.Name, wo => wo.Name)
                .Map(tpgdle => tpgdle.Type, wo => wo.Type)
                .Map(tpgdle => tpgdle.LineNameOrDeviceName, wo => wo.Type.Equals("巡检工单") ? wo.TaskInfo.ToObject<XunJianPlan>().Name : (wo.Type.Equals("保养工单") ? string.Join(",", wo.TaskInfo.ToObject<BaoYangPlan>().BaoYangDevices.Select(byd => byd.Name).ToArray()) : string.Join(",", wo.TaskInfo.ToObject<DianJianPlan>().DianJianDevices.Select(djd => djd.Name).ToArray())))
                .Map(tpgdle => tpgdle.Names, wo => wo.EpRealnames)
                .Map(tpgdle => tpgdle.Extra, wo => wo.Extra + "计划")
                .Map(tpgdle => tpgdle.BeginTime, wo => wo.SjBeginTime)
                .Map(tpgdle => tpgdle.EndTime, wo => wo.SjEndTime)
                .Map(tpgdle => tpgdle.Status, wo => wo.Status);
        }
    }
}
